package fs.ls.gs;

import java.sql.*;

/**
 * @Auther: zhezhe
 * @Date: 2018/9/1514:09
 * @Description:
 */
public class Test01 {
    public static void main(String[] args) {
        PreparedStatement pstmt = null;
        Connection conn = null;

      //  ResultSet rs = null;
        try {
            Class.forName("com.mysql.jdbc.Driver");

            conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/goods?useUnicode=true&characterEncoding=utf8&serverTimezone=UTC", "root", "root");
            pstmt = conn.prepareStatement("INSERT INTO goodstb(goods_name,goods_price,goods_num) values (?,?,?)");
            //String sql ="INSERT INTO goodstb(goods_name,goods_price,goods_num) values ('li','34','45');";
            pstmt.setString(1,"banana");
            pstmt.setDouble(2,54.0);
            pstmt.setDouble(3,34.0);
            pstmt.executeUpdate();

//            rs = stmt.executeQuery("select * from goodstb");
//            while (rs.next()) {
//                System.out.println(rs.getString("goods_name"));
//                System.out.println(rs.getInt("id"));
//                System.out.println(rs.getDouble("goods_price"));
//                System.out.println(rs.getInt("goods_num"));
//
//            }
        } catch (SQLException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } finally {
            try {
//                if (rs != null) {
//                    rs.close();
//                    rs = null;
//                }
                if (pstmt != null) {
                    pstmt.close();
                    pstmt = null;
                }

                if (conn != null) {
                    conn.close();
                    conn = null;
                }

            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }
}


